//
//  LoginViewController.m
//  02-HomeWork
//
//  Created by dllo on 16/7/15.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "LoginViewController.h"
#import "RegisterViewController.h"
#import "FogotPasswordViewController.h"
@interface LoginViewController () <UITextFieldDelegate>
@property (nonatomic, strong) UITextField *userTextField;
@property (nonatomic, strong) UITextField *passwordTextField;
@end

@implementation LoginViewController
- (void)viewWillAppear:(BOOL)animated {
     self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    self.navigationController.navigationBar.hidden = YES;
}
//login
- (void)viewDidLoad {
    [super viewDidLoad];
       self.navigationController.navigationBar.translucent = YES;
    self.navigationItem.title = @"登录页面";
    self.navigationController.navigationBar.tintColor = [UIColor grayColor];
    // Do any additional setup after loading the view.
    [self createBackGround];
    
    //logo
    UIImageView *logoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 2, 70, 180, 220)];
    CGPoint point = logoImageView.center;
    point.x = self.view.frame.size.width / 2;
    logoImageView.center = point;
    logoImageView.image = [UIImage imageNamed:@"logo_lagou@2x.png"];
    [self.view addSubview:logoImageView];
    //输入框
    UILabel *inputLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 300, self.view.frame.size.width - 20, 110)];
    //    inputLabel.backgroundColor = [UIColor whiteColor];
    inputLabel.layer.cornerRadius = 4;
    inputLabel.clipsToBounds = YES;
    //    inputLabel.layer.borderWidth = 4;
    //    label和imageView都要开用户交互
    inputLabel.userInteractionEnabled = YES;
    [self.view addSubview:inputLabel];
    // 用户登录
    UIImageView *userLoginImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
    userLoginImageView.image = [UIImage imageNamed:@"icon_username@2x.png"];
    userLoginImageView.backgroundColor = [UIColor colorWithRed:0.16 green:0.11 blue:0.06 alpha:1.00];
    [inputLabel addSubview:userLoginImageView];
    self.userTextField = [[UITextField alloc] initWithFrame:CGRectMake(50, 0, 310, 50)];
    self.userTextField.backgroundColor = [UIColor grayColor];
    self.userTextField.alpha = 0.4;
    self.userTextField.textColor = [UIColor whiteColor];
    self.userTextField.placeholder = @"请输入已验证的手机号或邮箱";
    self.userTextField.textColor = [UIColor whiteColor];
    self.userTextField.delegate = self;
    [inputLabel addSubview:self.userTextField];
    
    UIImageView *passwordImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 60, 50, 50)];
    passwordImageView.image = [UIImage imageNamed:@"icon_password@2x.png"];
    passwordImageView.backgroundColor = [UIColor colorWithRed:0.16 green:0.11 blue:0.06 alpha:1.00];
    [inputLabel addSubview:passwordImageView];
    self.passwordTextField = [[UITextField alloc] initWithFrame:CGRectMake(50, 60, 310, 50)];
    
    self.passwordTextField.backgroundColor = [UIColor grayColor];
    self.passwordTextField.alpha = 0.4;
    self.passwordTextField.placeholder = @"请输入密码";
    self.passwordTextField.delegate = self;
    [inputLabel addSubview:self.passwordTextField];
  // 忘记密码
    UIButton *forgotPasswordButton = [UIButton buttonWithType:UIButtonTypeCustom];
    forgotPasswordButton.frame = CGRectMake(200, 420, 150, 50);
    [forgotPasswordButton setTitle:@"忘记密码" forState:UIControlStateNormal];
    [forgotPasswordButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [forgotPasswordButton setImage:[UIImage imageNamed:@"question.png"] forState:UIControlStateNormal];
    [forgotPasswordButton addTarget:self action:@selector(forgotPasswordButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:forgotPasswordButton];
    
    // 返回登录
    UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
    loginButton.frame = CGRectMake(20, 460, self.view.frame.size.width - 40, 40);
    loginButton.layer.cornerRadius = 4;
    loginButton.backgroundColor = [UIColor colorWithRed:0.00 green:0.68 blue:0.53 alpha:1.00];
    [loginButton setTitle:@"登录" forState:UIControlStateNormal];
    [loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [loginButton addTarget:self action:@selector(loginButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:loginButton];
    // 注册按钮
    UIButton *registerButton = [UIButton buttonWithType:UIButtonTypeCustom];
    registerButton.frame = CGRectMake(20, 530, self.view.frame.size.width - 40, 40);
    registerButton.layer.cornerRadius = 4;
    registerButton.layer.borderWidth = 2;
    registerButton.layer.borderColor = [UIColor colorWithRed:0.00 green:0.68 blue:0.53 alpha:1.00].CGColor;
    [registerButton setTitle:@"注册拉勾" forState:UIControlStateNormal];
    [registerButton setTitleColor:[UIColor colorWithRed:0.00 green:0.68 blue:0.53 alpha:1.00] forState:UIControlStateNormal];
    [registerButton addTarget:self action:@selector(registerButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:registerButton];
    
}
 //backGround
- (void)createBackGround{
   
    UIImageView *backGroundImageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    backGroundImageView.image = [UIImage imageNamed:@"welcome_2.jpg"];
    [self.view addSubview:backGroundImageView];
}

- (void)forgotPasswordButtonClicked {
    FogotPasswordViewController *fogotPasswordViewController = [[FogotPasswordViewController alloc] init];
    [self.navigationController pushViewController:fogotPasswordViewController animated:YES];
    
}
  //点击注册收起键盘
- (void)registerButtonClicked {
    RegisterViewController *registerViewController = [[RegisterViewController alloc] init];
    [self.navigationController pushViewController:registerViewController animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
  // 收起键盘的方式
   // 点击return收起键盘
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField endEditing:YES];
    return YES;
}
  // 点击空白处收起键盘
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    if (![self.userTextField isExclusiveTouch] || ![self.passwordTextField isExclusiveTouch]) {
        [self.userTextField resignFirstResponder];
        [self.passwordTextField resignFirstResponder];
    }
}
  // 点击登录按钮收起键盘
- (void)loginButtonClicked {
    [self.userTextField resignFirstResponder];
    [self.passwordTextField resignFirstResponder];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
